### 一，

print("单号:  DH201409230001")

print("时间:  2014-09-23 08:56:14")

print("-------------------------")

print("名称"+"\t","数量","单价"+"  "+"金额")

print("金士顿U盘"+"\n"+"8GB"+"\t","1","40.00","40.00",sep="  ")

print("胜利16GBTF"+"\n"+"卡"+"\t","1","50.00","50.00",sep="  ")

print("读卡器"+"\t  "+"1"+"  "+"8.00"+"   "+"8.00")

print("网线2米"+"\t  "+"1"+"  "+"8.00"+"   "+"8.00")

print("-------------------------")

print("总数: 4      总额:103.00")

print("折后总额:103.00")

print("实收:103.00   找零:0.00")

print("收银: 管理员")

### 二，

print("           植树证书1          ")



print("            谢谢你            ")



print("你于2019年11月3日申请种植的梭梭树,\n已被中国抉贫基金会认领,将种植到武威\n地区。")



print("            树苗编号"+"\n"+"        NO.HFK20308960305")

### 三，

c = float(input("请输入摄氏温度:"))



k = c + 273.15



print(c,"°C","对应的开尔文:",k,"K",sep="")

### 四，

height = float(input("请输入身高(m):"))



weight = float(input("请输入体重(kg):"))



BMI = weight / (height**2)



print("你的身体质量指数为:",BMI,sep="")

### 五.

def calculator(pram_one, pram_two):
    operator = input('请选择要执行的运算符：+、-、*、/:' + '\n')
    if operator=="+":
        print("计算结果为:",pram_one+pram_two,sep="")
    elif operator=="-":
        print("计算结果为:",pram_one-pram_two,sep="")
    elif operator=="*":
        print("计算结果为:",pram_one*pram_two,sep="")
    elif operator=="/":
        if pram_two==0:
            print("被除数不能为0"+",请重新输入。")
        else:
            print("计算结果为:",pram_one/pram_two,sep="")

num_one = float(input("请输入第一个数:"))
num_two = float(input("请输入第二个数:"))
calculator(num_one,num_two)


### 六.

print("你有5次猜数字")
i = 1
correct_num = int(input("请设定猜数的数字:"))
while i <= 5:
    num = int(input("第"+str(i)+ "次猜的数字为:"))
    if num < correct_num:
        print("很遗憾，你猜小了。")
        if i >= 1 and i <= 4:
            print("你还剩", 5-i, "次机会。", sep="")
    elif num > correct_num:
        print("很遗憾，你猜大了。")
        if i >= 1 and i <= 4:
            print("你还剩", 5-i, "次机会。", sep="")
    elif num == correct_num:
        print("恭喜，猜数成功。")
    i = i + 1
    if i == 6 and (num < correct_num or num > correct_num):
        print("对不起，你输了。")


### 七.
for i in range(1,101):
    if i % 7==0 or "7" in str(i):
       print(i,end=" ")


### 八.

size = int(input("请输入棋盘大小:"))
for i in range(size):
    for j in range(size):
        if i==0 and j==0:
            print("┌-",end="")
        elif i==0 and j==size-1:
            print("-┐",end="")
        elif i==size-1 and j==0:
            print("└-",end="")
        elif i ==size-1 and j==size-1:
            print("-┘",end="")
        elif j ==0:
            print("├-",end="")
        elif i==size-1:
            print("-┴-",end="")
        elif j==size-1:
            print("-┤",end="")
        elif i==0:
            print("-┬-",end="")
        else:
            print("-┼-",end="")
    print("")


### 九.

while True:
    loan_type = str(input("请选择贷款类型:1.商业贷款 2.公积金贷款 3.组合贷款 0.退出\n"))
    if loan_type == "0":
        break
    elif loan_type == "1":
        loan_amount = float(input("请输入贷款金额（万）\n"))
        term = int(input("请选择期限(年):5、10、15、20、25\n"))
        if term in [5, 10, 15, 20, 25]:
            if term == 5:
                mon_rate = (4.75 / 100) / 12
                mon_pay = loan_amount * 10000 * (mon_rate * ((1 + mon_rate) ** (term * 12))) / (
                    ((1 + mon_rate) ** (term * 12)) - 1)
                all_pay = mon_pay * term * 12
                interest = all_pay - loan_amount * 10000
                print("每月月供参考（元）：{:.2f}元".format(mon_pay))
                print("支付利息（元）：{:.2f}元".format(interest))
                print("还款总额（元）：{:.2f}元".format(all_pay))
            else:
                mon_rate = (4.90 / 100) / 12
                mon_pay = loan_amount * 10000 * \
                    (mon_rate * ((1 + mon_rate) ** (term * 12))) / \
                    (((1 + mon_rate) ** (term * 12)) - 1)
                all_pay = mon_pay * term * 12
                interest = all_pay - loan_amount * 10000
                print("每月月供参考（元）：{:.2f}元".format(mon_pay))
                print("支付利息（元）：{:.2f}元".format(interest))
                print("还款总额（元）：{:.2f}元".format(all_pay))
    elif loan_type == "2":
        loan_amount = float(input("请输入贷款金额（万）\n"))
        term = int(input("请选择期限(年):5、10、15、20、25\n"))
        if term in [5, 10, 15, 20, 25]:
            if term == 5:
                mon_rate = (2.75 / 100) / 12
                mon_pay = loan_amount * 10000 * (mon_rate * ((1 + mon_rate) ** (term * 12))) / (
                    ((1 + mon_rate) ** (term * 12)) - 1)
                all_pay = mon_pay * term * 12
                interest = all_pay - loan_amount * 10000
                print("每月月供参考（元）：{:.2f}元".format(mon_pay))
                print("支付利息（元）：{:.2f}元".format(interest))
                print("还款总额（元）：{:.2f}元".format(all_pay))
            else:
                mon_rate = (3.25 / 100) / 12
                mon_pay = loan_amount * 10000 * \
                    (mon_rate * ((1 + mon_rate) ** (term * 12))) / \
                    (((1 + mon_rate) ** (term * 12)) - 1)
                all_pay = mon_pay * term * 12
                interest = all_pay - loan_amount * 10000
                print("每月月供参考（元）：{:.2f}元".format(mon_pay))
                print("支付利息（元）：{:.2f}元".format(interest))
                print("还款总额（元）：{:.2f}元".format(all_pay))
    elif loan_type =="3":
        loan_amount1 = float(input("请输入商业贷款金额（万）\n"))
        loan_amount2 = float(input("请输入公积金贷款金额（万）\n"))       
        term = int(input("请选择期限(年):5、10、15、20、25\n"))
        if term in [5, 10, 15, 20, 25]:
            if term == 5:
                mon_rate1 = (4.75 / 100) / 12
                mon_pay1 = loan_amount1 * 10000 * (mon_rate1 * ((1 + mon_rate1) ** (term * 12))) / (
                    ((1 + mon_rate1) ** (term * 12)) - 1)
                all_pay1 = mon_pay1 * term * 12
                interest1 = all_pay1 - loan_amount1 * 10000
                mon_rate2 = (2.75 / 100) / 12 
                mon_pay2 = loan_amount2 * 10000 * (mon_rate2 * ((1 + mon_rate2) ** (term * 12))) / (
                    ((1 + mon_rate2) ** (term * 12)) - 1)
                all_pay2 = mon_pay2 * term * 12
                interest2 = all_pay2 - loan_amount2 * 10000       
                mon_pay = mon_pay1 + mon_pay2
                interest = interest1 + interest2
                all_pay = all_pay1 + all_pay2
                print("每月月供参考（元）:{:.2f}元".format(mon_pay))
                print("支付利息（元）:{:.2f}元".format(interest))
                print("还款总额（元）:{:.2f}元".format(all_pay))               
            else:
                mon_rate1 = (4.90 / 100) / 12
                mon_pay1 = loan_amount1 * 10000 * (mon_rate1 * ((1 + mon_rate1) ** (term * 12))) / (
                    ((1 + mon_rate1) ** (term * 12)) - 1)
                all_pay1 = mon_pay1 * term * 12
                interest1 = all_pay1 - loan_amount1 * 10000
                mon_rate2 = (3.25 / 100) / 12
                mon_pay2 = loan_amount2 * 10000 * (mon_rate2 * ((1 + mon_rate2) ** (term * 12))) / (
                    ((1 + mon_rate2) ** (term * 12)) - 1)
                ll_pay2 = mon_pay2 * term * 12
                interest2 = all_pay2 - loan_amount2 * 10000       
                mon_pay = mon_pay1 + mon_pay2
                interest = interest1 + interest2
                all_pay = all_pay1 + all_pay2
                print("每月月供参考（元）：{:.2f}元".format(mon_pay))
                print("支付利息（元）：{:.2f}元".format(interest))
                print("还款总额（元）：{:.2f}元".format(all_pay)) 
    else:
        print("无效的贷款类型，请重新输入")
        continue   









# 十 进制转换
while True:
    print("----------------菜单-----------------")
    start_end = int(input("1.开始 0.退出\n"))
    if start_end == 1:
        number = int(input("请输入数字:"))
        choose = int(input("请选择要转换的数字类型:1.二进制 2.八进制 3.十六进制\n"))
        if choose == 1:
            str = str(bin(number))
            newStr = str.lstrip("0b")
            print("{}转换二进制数为:{}".format(number,newStr))
        elif choose == 2:
            print(number, "转换八进制数为:%o"%number)
        elif choose == 3:
            print(number, "转换十六进制数为:%x"%number)
    elif start_end == 0:
        print("已成功退出,感谢您使用。")
        break





# 十一，文本进度条
import time
incomplete_sign = 50
print("="*23+"开始下载"+"="*25)
for i in range(incomplete_sign + 1):
    completed = "*" * i
    incomplete = "." * (incomplete_sign - i)
    percentage = (i / incomplete_sign) * 100
    print("\r{:.0f}%[{}{}]".format(percentage, completed, incomplete), end="")
    time.sleep(0.5)
print("\n"+"="*23+"下载完成"+"="*25)




# 十二,敏感词的替换
Sensitivet_hesaurus = ("傻逼","nmsl","awsl","wcnm")
Old_statement = str(input("请输入:"))
for i in Sensitivet_hesaurus:
     if i in Old_statement:
         New_statement  = Old_statement.replace(i,"***")
print(New_statement)




# 十二,敏感词的替换
Sensitivet_hesaurus = ("傻逼","nmsl","awsl","wcnm")
Old_statement = str(input("请输入:"))
for i in Sensitivet_hesaurus:
     if i in Old_statement:
         New_statement  = Old_statement.replace(i,"***")
print(New_statement)






# 十三,文字排版工具
string = '他问,你知道cba是什么单词的缩写么     ?'
print(string)
print('1.删除空格')
print('2.英文标点替换')
print('3.首字母大写')
print('4.退出')
while True:
    option = input('请输入功能选项:\n')
    if option == '1':
        string = string.replace(' ','')
        print(string)
    elif option == '2':
        for i in string:
            if i == ',':
                string = string.replace(',','，')
            elif i == '.':
                string = string.replace('.','。')
            elif i == '?':
                string = string.replace('?','？')
        string = string
        print(string)
    elif option == '3':
        string = string.upper()
        print(string)
    elif option == '4':
        break







# 十四,唐诗三百首
import jieba
with open('唐诗三百首.txt','r',encoding='utf-8') as fr:
    txt = fr.read()
words = jieba.lcut(txt)
counts = {}
for word in words:
    counts[word] = counts.get(word,0)+1
items = list(counts.items())
items.sort(key = lambda x:x[1],reverse=True)
for i in range(30):
    word,count = items[i]
    print('{0:<10}{1:>5}'.format(word,count))
    
    
    
    
    
# 十五,十大歌手

score_li = []
total_score = 0
for i in range(1,11):
    score = float(input(f'请第{i}位评委输入评分：\n'))
    score_li.append(score)
score_li.sort()
print(f'去掉最高分：{score_li[0]}')
print(f'去掉最低分：{score_li[len(score_li)-1]}')
score_li.remove(score_li[0])
score_li.pop()
for j in score_li:
    total_score += j
print(f'选手最终得分为：{total_score/(len(score_li))}') 







#十六,神奇魔方阵


n = 5
magic_square = [[0 for x in range(n)] for y in range(n)]
i = n / 2
j = n - 1
num = 1
while num <= (n * n):
    if i == -1 and j == n:
        j = n - 2
        i = 0
    else:
        if j == n:
            j = 0
        if i < 0:
            i = n - 1
    if magic_square[int(i)][int(j)]:
        j = j - 2
        i = i + 1
        continue
    else:
        magic_square[int(i)][int(j)] = num
        num = num + 1
    j = j + 1
    i = i - 1
for i in range(0,n):
    for j in range(0,n):
        print('%2d' % (magic_square[i][j]),end = ' ')
        if j == n - 1:
            print()






#十七,青春有你



play_info = {}
li = []
print('输入quit表示选手成绩录入完毕')
while True:
    name = input('请输入选手名称：\n')
    if name == 'quit':
        break
    score = float(input('请输入选手票数：\n'))
    play_info[name] = score
items = play_info.items()
for j in items:
    li.append([j[1],j[0]])
li.sort()
count = len(li) - 1
for i in range(1,len(li) + 1):
    print(f'第{i}名：{li[count][1]},成绩为{li[count][0]}分')
    count -= 1








#十八,手机通讯录


person_info =[]
print('=' * 20)
print('1.添加联系人')
print('2.查看通讯录')
print('3.删除联系人')
print('4.修改联系人信息')
print('5.查找联系人')
print('6.退出')
while True:
    per_dict = {}
    fun_num = input('请输入功能序号：')
    if fun_num == '1':
        per_name = input('请输入联系人的姓名：')
        phone_num = input('请输入联系人的手机号：')
        per_email = input('请输入联系人的邮箱：')
        per_address = input('请输入联系人的地址：')
        if per_name.strip() == '':
            print('请输入正确信息')
            continue
        else:
            per_dict.update({'姓名':per_name,
                             '手机号':phone_num,
                             '电子邮箱':per_email,
                             '联系地址':per_address})
            person_info.append(per_dict)
            print('保存成功')
    elif fun_num == '2':
        if len(person_info) == 0:
            print('通讯录无信息')
        for i in person_info:
            for title, info in i.items():
                print(title + ':' + info)
    elif fun_num == '3':
        if len(person_info) != 0:
            del_name = input('请输入要删除的联系人姓名：')
            for i in person_info:
                if del_name in i.values():
                    person_info.remove(i)
                    print(person_info)
                    print('删除成功')
                else:
                    print('该联系人不在通讯录中')
        else:
            print('通讯录无信息')
    elif fun_num == '4':
        if len(person_info) != 0:
            modi_info = input('请输入要修改的联系人姓名：')
            for i in person_info:
                if modi_info in i.values():
                    index_num = person_info.index(i)
                    dict_cur_perinfo = person_info[index_num]
                    for title, info in dict_cur_perinfo.items():
                        print(title + ':' + info) 
                    modi_name = input('请输入新的姓名：')
                    modi_phone = input('请输入新的手机号：')
                    modi_email = input('请输入新的邮箱：')
                    modi_address = input('请输入新的地址：')
                    dict_cur_perinfo.update(姓名 = modi_name)
                    dict_cur_perinfo.update(手机号 = modi_phone)
                    dict_cur_perinfo.update(电子邮箱 = modi_email)
                    dict_cur_perinfo.update(联系地址 = modi_address)
                    print(person_info)
        else:
                    print('通讯录无信息')
    elif fun_num == '5':
        if len(person_info) != 0:
            query_name = input('请输入要查找的联系人姓名：')
            for i in person_info:
                if query_name in i.values():
                    index_num = person_info.index(i)
                    for title, info in person_info[index_num].items():
                        print(title + ':' + info)
                    break
            else:
                print('该联系人不在通讯录中')
        else:
            print('通讯录无信息')
    elif fun_num == '6':
        break
        

